package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.dictionary.WarehouseOriStockEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 仓库
 *
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/19
 * @since v1.0
 */
@Getter
public enum TempWarehouseEnum {
    //
    BASE_INFO(WarehouseEnum.BASE_INFO),
    WAREHOUSE_NAME(WarehouseEnum.WAREHOUSE_NAME),
    WAREHOUSE_NO(WarehouseEnum.WAREHOUSE_NO),
    ADDRESS(WarehouseEnum.ADDRESS),
    MANAGER_DEP_ID(WarehouseEnum.MANAGER_DEP_ID),
    MANAGER_ID(WarehouseEnum.MANAGER_ID),
    MEMO(WarehouseEnum.MEMO),
    SENDER_INFORMATION(WarehouseEnum.SENDER_INFORMATION),
    SENDER_DATAILS(WarehouseEnum.SENDER_DETAILS),
    ORI_STOCK(WarehouseEnum.ORI_STOCK),

    SYSTEM_INFO(WarehouseEnum.SYSTEM_INFO),
    CREATOR_ID(WarehouseEnum.CREATOR_ID),
    ADD_TIME(WarehouseEnum.ADD_TIME),
    UPDATE_TIME(WarehouseEnum.UPDATE_TIME),

    IS_DEFAULT(WarehouseEnum.IS_DEFAULT),
    LATITUDE(WarehouseEnum.LATITUDE),
    LONGITUDE(WarehouseEnum.LONGITUDE),
    CONTACT_ID(WarehouseEnum.CONTACT_ID),
    CONTACT_NAME(WarehouseEnum.CONTACT_NAME),
    CONTACT_NUMBER(WarehouseEnum.CONTACT_NUMBER),
    ;

    private WarehouseEnum anEnum;

    TempWarehouseEnum(WarehouseEnum warehouseEnum) {
        this.anEnum = warehouseEnum;
    }

    public static void initSenderDetails(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "寄件人", "type", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        item.setRequired(1);
        item.setParentAttr(WarehouseEnum.SENDER_DETAILS.getAttr());
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField("text_2", "联系电话", "phone", FieldTypeEnum.TEXT.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        item2.setNoRepeat(1);
        item2.setRequired(1);
        item2.setParentAttr(WarehouseEnum.SENDER_DETAILS.getAttr());
        items.add(item2);
        fieldAttrEntity.setSubForm(subFormPoJo);
        FieldAttrEntity item3 = InitExplainsHelper.setField("address_1", "地址", "address", FieldTypeEnum.ADDRESS.getType(), 4, ShowTypeEnum.ALL.getCode(), 0, 1);
        item3.setRequired(1);
        item3.setEditable(1);
        item.setParentAttr(WarehouseEnum.SENDER_DETAILS.getAttr());
        items.add(item3);
        subFormPoJo.setItems(items);
    }

    public static List<TempWarehouseEnum> getAllEnum() {
        java.util.List<TempWarehouseEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    /**
     * 初始化仓库名称
     *
     * @param fieldAttrEntity 字段属性
     * @author feng.zheng
     * @date 2019/2/16 15:52
     */
    public static void initWarehouseName(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.WAREHOUSE.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.WAREHOUSE.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(WAREHOUSE_NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 初始化仓库编号
     *
     * @param fieldAttrEntity 字段属性
     * @author feng.zheng
     * @date 2019/2/16 15:52
     */
    public static void initWarehouseNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.WAREHOUSE.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.WAREHOUSE.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(WAREHOUSE_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.WAREHOUSE_NO));
        fieldAttrEntity.setIsForbidden(0);
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initManagerDepId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initManagerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }
//    /**
//    * @Description: 初始化期初库存下拉框选项
//    * @Param: []
//    * @return: void
//    * @Author: cyy
//    * @Date: 2019/10/9
//    */
//    public static void initOriStock(FieldAttrEntity fieldAttrEntity){
//        List<ItemPoJo> items = new ArrayList<>();
//        ItemPoJo notDone = new ItemPoJo(WarehouseOriStockEnum.NOT_DONE.getName(),WarehouseOriStockEnum.NOT_DONE.getName(),true);
//        ItemPoJo noNeed = new ItemPoJo(WarehouseOriStockEnum.NO_NEED.getName(),WarehouseOriStockEnum.NO_NEED.getName());
//        items.add(notDone);
//        items.add(noNeed);
//        fieldAttrEntity.setItems(items);
//    }
    /**
     * 初始化期初库存状态
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initOriStock(FieldAttrEntity fieldAttrEntity) {
        List<ItemPoJo> itemPoJos = InitExplainsHelper.setCombItemByEnum(WarehouseOriStockEnum.class, fieldAttrEntity.getFieldType());
        for (int i = 0; i < itemPoJos.size(); i++) {
            ItemPoJo itemPoJo = itemPoJos.get(i);
            itemPoJo.setNoDel(1);
            itemPoJo.setNoEdit(1);
            if (Objects.equals(itemPoJo.getText(),WarehouseOriStockEnum.NOT_DONE.getName())){
                itemPoJo.setChecked(true);
            }
        }
        fieldAttrEntity.setItemBanDefault(1);
        fieldAttrEntity.setDictionaryFlag(0);
        fieldAttrEntity.setItems(itemPoJos);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditForbidden(0);
        fieldAttrEntity.setAdvancedSetHide(1);
        fieldAttrEntity.setShowEditable(1);
    }

}
